/*************************************************
Author: Aven 
Date: 2/25/2013
Description:
Notes: 
*************************************************/

#ifndef __CMagicDoorConfig_h__
#define __CMagicDoorConfig_h__

#include "CTArray.h"
#include "../maindef.h"
#include "commclass.h"

class CLevelGiftUnit
{
public:
    CLevelGiftUnit()
    {
        Clear();
    }

    virtual ~CLevelGiftUnit()
    {
    }

    void Clear()
    {
        _iGiftID = 0;
        _iGiftNum = 0;
    }

    int GetGiftID() const {return _iGiftID;}
    int GetGiftNum() const {return _iGiftNum;}

    void SetGiftID(int iVal) {_iGiftID = iVal;}
    void SetGiftNum(int iVal) {_iGiftNum = iVal;}

private:
    int     _iGiftID;
    int     _iGiftNum;
};

//魔界门等级配置 
class CMagicDoorLevelCfgData
{
public:
    CMagicDoorLevelCfgData()
    {
        Clear();
    }

    virtual ~CMagicDoorLevelCfgData()
    {
    }

    void Clear()
    {
        _iLevel = -1;//必须负值因0为合理值
        _iNeedExp = 0;
        _iContributeAward = 0;
        _iSpecialBoss = 0;
        _iBossNum = 0;
        _aiContriGift.Clear();
        _astActGift.Clear();
    }

    bool IsValidLevel()
    {
        return (_iLevel >= 0 && _iLevel <= MAGIC_DOOR_MAX_LEVEL);
    }

    bool IsValidData()
    {
        if (_iBossNum < 0 || _iBossNum > MAX_MAGIC_DOOR_BOSS_NUMS)
        {
            return false;
        }

        for (int i = 0; i < _astActGift.Size(); ++i)
        {
            if (_astActGift[i].GetGiftNum() < 0)
            {
                return false;
            }
        }

        return true;
    }

    int GetLevel() const {return _iLevel;}
    int GetNeedExp() const {return _iNeedExp;}
    int GetContributeAward() const {return _iContributeAward;}
    int GetSpecialBoss() const {return _iSpecialBoss;}
    int GetBossNum() const {return _iBossNum;}
    int GetContriGiftSize() const {return _aiContriGift.Size();}
    int GetContriGiftID(int iIndex) const {return _aiContriGift[iIndex];}
    int GetActGiftSize() const {return _astActGift.Size();}
    CLevelGiftUnit& GetActGift(int iIndex) {return _astActGift[iIndex];}

    void SetLevel(int iVal) {_iLevel = iVal;}
    void SetNeedExp(int iVal) {_iNeedExp = iVal;}
    void SetContributeAward(int iVal) {_iContributeAward = iVal;}
    void SetSpecialBoss(int iVal) {_iSpecialBoss = iVal;}
    void SetBossNum(int iVal) {_iBossNum = iVal;}

    void AddContriGift(int iVal) {_aiContriGift.AddOneItem(iVal);}
    void AddActGift(CLevelGiftUnit& stUnit) {_astActGift.AddOneItem(stUnit);}

private:
    int _iLevel;           //魔界门的等级
    int _iNeedExp;       //升级需要经验值
    int _iContributeAward; //升至此级奖励多少贡献度
    int _iSpecialBoss;     //刷出特殊boss概率
    int _iBossNum;         //开门时boss的数量

    CTLib::CTArray<int, MAX_CONTRIBUTE_LIST> _aiContriGift;
    CTLib::CTArray<CLevelGiftUnit, MAGIC_DOOR_LEVEL_ACT_GIFT_COUNT> _astActGift;
};

//充能贡献度
class CMagicDoorConsumeCfgData
{
public:
    CMagicDoorConsumeCfgData()
    {
        Clear();
    }

    virtual ~CMagicDoorConsumeCfgData()
    {
    }

    void Clear()
    {
        _iTimes = 0;
        _iSubContribute = 0;
    }

    bool IsValidTime()
    {
        return (_iTimes > 0 && _iTimes <= MAGIC_DOOR_MAX_PAY_TIMES);
    }

    int GetTimes() const {return _iTimes;}
    int GetSubContribute() const {return _iSubContribute;}

    void SetTimes(int iVal) {_iTimes = iVal;}
    void SetSubContribute(int iVal) {_iSubContribute = iVal;}

private:
    int _iTimes;           //充能次数
    int _iSubContribute;   //当前次数消耗贡献度
};

//魔界门配置
class CMagicDoorConfig
{
public:
	CMagicDoorConfig() 
    {
        Clear();
	}

    void Clear()
    {
        _astLevelConfig.m_iUsedCount = _astLevelConfig.GetCount();
        for (int i = 0; i < _astLevelConfig.Size(); ++i)
        {
            _astLevelConfig[i].Clear();
        }

        _astConsumeConfig.m_iUsedCount = _astConsumeConfig.GetCount();
        for (int i = 0; i < _astConsumeConfig.Size(); ++i)
        {
            _astConsumeConfig[i].Clear();
        }
    }

	virtual ~CMagicDoorConfig() 
    {
	}

    int AddLevelConfig(CMagicDoorLevelCfgData& stData);
    int FindLevelConfig(int iLevel);
    CMagicDoorLevelCfgData& GetLevelConfig(int iIndex);

    int AddConsumeConfig(CMagicDoorConsumeCfgData& stData);
    int FindConsumeConfig(int iTimes);
    CMagicDoorConsumeCfgData& GetConsumeConfig(int iIndex);

private:
    CTLib::CTArray<CMagicDoorLevelCfgData, MAGIC_DOOR_LEVEL_CFG_COUNT> _astLevelConfig;   //魔界门等级配置
    CTLib::CTArray<CMagicDoorConsumeCfgData, MAGIC_DOOR_CONTRIBUTE_CFG_COUNT> _astConsumeConfig;      //充能消耗贡献度配置
};

#endif // __CMagicDoorConfig_h__

